package br.gov.ms.tce.cjur.acao;

import java.util.HashSet;
import java.util.List;
import java.util.ResourceBundle;
import java.util.Set;

import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.validation.ConstraintViolation;

public abstract class AbstractMb {

	private ResourceBundle bundle;
	
	protected void setMsgInfo(List<String> msgs) {		
		for (String msg : msgs) 
			FacesContext.getCurrentInstance().addMessage(null,new FacesMessage(FacesMessage.SEVERITY_INFO, getBundle().getString(msg),null));		
	}
	
	protected void setMsgInfo(String msg) {
		FacesContext.getCurrentInstance().addMessage(null,new FacesMessage(FacesMessage.SEVERITY_INFO, getBundle().getString(msg),null));		
	}

	@SuppressWarnings({ "rawtypes", "unchecked" })
	protected void setMsgErro(Set erros) {
		for(ConstraintViolation erro : new HashSet<ConstraintViolation>(erros)){
			FacesContext.getCurrentInstance().addMessage(erro.getPropertyPath().toString(), new FacesMessage(FacesMessage.SEVERITY_ERROR,erro.getPropertyPath().toString()+"="+erro.getInvalidValue().toString(), getBundle().getString(erro.getMessage())));
		}
	}

	

	/**
	 * @return Retorna o valor da propriedade bundle
	 */
	public ResourceBundle getBundle() {
		if(bundle == null){
			bundle = ResourceBundle.getBundle("messages");
		}
		return bundle;
	}

	/**
	 * @param Configura o valor da propriedade bundle
	 */
	public void setBundle(ResourceBundle bundle) {
	
		this.bundle = bundle;
	}
	
	

	
		
	
}
